package com.cjjd.c.feature.mine.information;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cjjd.c.R;
import com.cjjd.c.base.ActionBarFragment;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/18.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class InformationFragment extends ActionBarFragment {
    @Bind(R.id.tablayout)
    TabLayout tablayout;
    @Bind(R.id.viewpager)
    ViewPager viewpager;

    @Override
    public Object getTitleString() {
        return "常用信息";
    }

    @Override
    public int getContentView() {
        return R.layout.activity_informaion;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);

        initView();
        return rootView;
    }


    private Fragment travellerFragment = null;
    private Fragment addressFragment = null;
//    private Fragment contactFragment = null;
    private Fragment receiptFragment = null;

    @Override
    protected void initView() {
        super.initView();
        viewpager.setAdapter(new FragmentStatePagerAdapter(getChildFragmentManager()) {

            private String[] mTitles = new String[]{"旅客", "地址",  "发票管理"};

            @Override
            public Fragment getItem(int position) {
                if (position == 0) {
                    if (travellerFragment != null) {
                        return travellerFragment;
                    } else {
                        return new TravellerFragment();
                    }
                } else if (position == 1) {
                    if (addressFragment != null) {
                        return addressFragment;
                    } else {
                        return new AddressFragment();
                    }
                }  else {
                    if (receiptFragment != null) {
                        return receiptFragment;
                    } else {
                        return new ReceiptManagerFragment();
                    }
                }
            }

            @Override
            public int getCount() {
                return mTitles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitles[position];
            }
        });

        tablayout.setupWithViewPager(viewpager);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tablayout, R.id.viewpager})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tablayout:
                break;
            case R.id.viewpager:
                break;
        }
    }
}
